
import 'package:appflutter/day12_%E8%B7%AF%E7%94%B1%E5%AF%BC%E8%88%AA/routes/unKnown_page.dart';

import 'routes/secondPage.dart';
import 'package:flutter/material.dart';

main() => runApp(myApp());

class myApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(primaryColor: Colors.blue),
      routes: {
        '/': (conntext) => MyHomePage(),
        second.routename: (context) => second()
      },
      initialRoute: '/',
      onUnknownRoute: (setting) {
        return MaterialPageRoute(builder: (context) => unKnown_page());
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String message = '666';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('首页'),
        elevation: 0,
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RaisedButton(
              onPressed: () {
                final future = Navigator.pushNamed(context, second.routename,
                    arguments: '这是一条传递得message');
                future.then((res) {
                  setState(() {
                    print(res);
                    message = res;
                  });
                });
              },
              child: Text(
                '跳转',
                style: TextStyle(color: Colors.white),
              ),
              color: Colors.pink,
            ),
            Text(message),
            RaisedButton(onPressed: (){

              Navigator.of(context).pushNamed('routeName');

            },
            child: Text('跳转错误页面'),
            )
          ],
        ),
      ),
    );
  }
}
